package hashtable;

import java.util.HashMap;
import java.util.Map;

public class 两数之和_1 {
            public int[] twoSum(int[] nums, int target) {
                Map<Integer, Integer> map= new HashMap<>(); // remain idx
                for(int i = 0; i< nums.length; i++) {
                    Integer remain = target - nums[i];
                    Integer index = map.get(nums[i]);
                    if(index != null) {
                        return new int[]{index, i};
                    }
                    map.put(remain, i);
                }
                return new int[]{};
            }
        }
